﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace iMainAddin.iItem
{
	class iManageVcFolder
	{
		//         XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Book");
		//Console.WriteLine("Here is the list of catalogs\n\n");

		//for(int i=0;i<xmlnode.Count;i++)
		//{
		//XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;

		////XML Attribute Name and Value returned
		////Example: <Book id = "001">

		//Console.Write(xmlattrc[0].Name);
		//Console.WriteLine(":\t"+xmlattrc[0].Value);

		////First Child of the XML file - Catalog.xml - returned
		////Example: <Author>Mark</Author>

		//Console.Write(xmlnode[i].FirstChild.Name);
		//Console.WriteLine(":\t"+xmlnode[i].FirstChild.InnerText);

		////Last Child of the XML file - Catalog.xml - returned
		////Example: <Publisher>Sams</Publisher>

		//Console.Write(xmlnode[i].LastChild.Name);
		//Console.WriteLine(":\t"+xmlnode[i].LastChild.InnerText);
		//Console.WriteLine();
		static void Main()
		{
			string filePath = @"..\..\booklist.xml";
			XmlDocument xDoc = new XmlDocument();
			xDoc.Load(filePath);

			XmlElement eBook = xDoc.DocumentElement;
			XmlElement eFirstBook = (XmlElement)eBook.FirstChild;
			XmlNodeList nlChilds = eFirstBook.ChildNodes;

			for (int i = 0; i < nlChilds.Count; i++)
			{
				XmlElement eChild = (XmlElement)nlChilds[i];
				Console.WriteLine(eChild.Name + ":" + eChild.InnerText);
			}
		}
		//        // New XML Element Created
//XmlElement newcatalogentry = xmldoc.CreateElement("Book");

//// New Attribute Created
//XmlAttribute newcatalogattr = xmldoc.CreateAttribute("ID");

//// Value given for the new attribute
//newcatalogattr.Value = "005";

//// Attach the attribute to the XML element
//newcatalogentry.SetAttributeNode(newcatalogattr);

//// First Element - Book - Created
//XmlElement firstelement = xmldoc.CreateElement("Book");

//// Value given for the first element
//firstelement.InnerText = "Peter";

//// Append the newly created element as a child element
//newcatalogentry.AppendChild(firstelement);


//// Second Element - Publisher - Created
//XmlElement secondelement = xmldoc.CreateElement("Publisher");

//// Value given for the second element
//secondelement.InnerText = "Que Publishing";

//// Append the newly created element as a child element
//newcatalogentry.AppendChild(secondelement);

//// New XML element inserted into the document
//xmldoc.DocumentElement.InsertAfter(newcatalogentry,
//                                   xmldoc.DocumentElement.LastChild);

//// An instance of FileStream class created
//// The first parameter is the path to the XML file - Catalog.xml

//FileStream fsxml = new FileStream(path,FileMode.Truncate,
//                                  FileAccess.Write,
//                                  FileShare.ReadWrite);

//// XML Document Saved
//xmldoc.Save(fsxml);
	}
}
